package com.example.warehousems.dao;

import com.example.warehousems.dao.model.Branch;
import com.example.warehousems.dao.model.Cargo;
import com.example.warehousems.dao.model.OutList;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;

public interface OutListRepository extends JpaRepository<OutList, Integer> {
    @Transactional
    @Modifying
    @Query("update OutList o set o.is_delete=true where o.id=:id")
    int setIsDeleteTrue(@Param("id") Integer id);

    OutList findOutListById(Integer id);

    @Query("select o from OutList o where o.branch = :branch and o.is_delete = :isDelete")
    List<OutList> findByBranchAndIs_delete(@Param("branch") Branch branch, @Param("isDelete") Boolean isDelete);

    @Query("select o from OutList o where o.branch = :branch and o.is_delete = :isDelete and o.is_available = :isAvailable")
    List<OutList> findByBranchAndIsDeleteAndIsAvailable(@Param("branch") Branch branch, @Param("isDelete") Boolean isDelete, @Param("isAvailable") Boolean isAvailable);
}
